package com.ruoyi.DataManage.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.DataManage.domain.Subject_tree;
import com.ruoyi.DataManage.domain.University;
import com.ruoyi.DataManage.mapper.CategoryMapper;
import com.ruoyi.DataManage.mapper.Subject_treeMapper;
import com.ruoyi.DataManage.mapper.UniversityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.DataManage.mapper.ExaminationCourseMapper;
import com.ruoyi.DataManage.domain.ExaminationCourse;
import com.ruoyi.DataManage.service.IExaminationCourseService;

/**
 * 考试科目管理Service业务层处理
 * 
 * @author CehnFneg
 * @date 2024-04-23
 */
@Service
public class ExaminationCourseServiceImpl implements IExaminationCourseService 
{
    @Autowired
    private ExaminationCourseMapper examinationCourseMapper;

    @Autowired
    private UniversityMapper universityMapper;

    @Autowired
    private Subject_treeMapper subject_treeMapper;

    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 查询考试科目管理
     * 
     * @param id 考试科目管理主键
     * @return 考试科目管理
     */
    @Override
    public ExaminationCourse selectExaminationCourseById(Long id)
    {
        return examinationCourseMapper.selectExaminationCourseById(id);
    }

    /**
     * 查询考试科目管理列表
     * 
     * @param examinationCourse 考试科目管理
     * @return 考试科目管理
     */
    @Override
    public List<ExaminationCourse> selectExaminationCourseList(ExaminationCourse examinationCourse)
    {
        return examinationCourseMapper.selectExaminationCourseList(examinationCourse);
    }

    /**
     * 新增考试科目管理
     * 
     * @param examinationCourse 考试科目管理
     * @return 结果
     */
    @Override
    public int insertExaminationCourse(ExaminationCourse examinationCourse)
    {
        //插入学校名称
        Long universityId = examinationCourse.getUniversityId();
        University university = universityMapper.selectUniversityById(universityId);
        examinationCourse.setUniversityName(university.getName());

        //插入专业名称
        Long majorId = examinationCourse.getMajorId();
        Subject_tree major = subject_treeMapper.selectSubject_treeById(majorId);
        examinationCourse.setMajorName(major.getName());

        return examinationCourseMapper.insertExaminationCourse(examinationCourse);
    }

    /**
     * 修改考试科目管理
     * 
     * @param examinationCourse 考试科目管理
     * @return 结果
     */
    @Override
    public int updateExaminationCourse(ExaminationCourse examinationCourse)
    {
        return examinationCourseMapper.updateExaminationCourse(examinationCourse);
    }

    /**
     * 批量删除考试科目管理
     * 
     * @param ids 需要删除的考试科目管理主键
     * @return 结果
     */
    @Override
    public int deleteExaminationCourseByIds(Long[] ids)
    {
        return examinationCourseMapper.deleteExaminationCourseByIds(ids);
    }

    /**
     * 删除考试科目管理信息
     * 
     * @param id 考试科目管理主键
     * @return 结果
     */
    @Override
    public int deleteExaminationCourseById(Long id)
    {
        return examinationCourseMapper.deleteExaminationCourseById(id);
    }

    @Override
    public List<ExaminationCourse> getCourseList() {
        return examinationCourseMapper.getCourseList();
    }

    @Override
    public List<ExaminationCourse> getCourseListByMajorId(Long majorId) {
        //经济学 工学 军事学 考数学
        //一、获取门类名称
        //1、获取学科Id
        Long subjectId =  subject_treeMapper.getParentIdByMajorId(majorId);
        //2、获取门类Id
        Long categoryId = subject_treeMapper.getCategoryIdBySubjectId(subjectId);
        //3、获取门类名称
        String categoryName = categoryMapper.selectCategoryById(categoryId).getName();
        //通识课程列表(去除数学）
        List<ExaminationCourse> CommonCourseList = examinationCourseMapper.getCommonCourseList();
        //通识课考数学的
        if("经济学".equals(categoryName) || "工学".equals(categoryName) || "军事学".equals(categoryName)){
            ExaminationCourse math = examinationCourseMapper.selectExaminationCourseById(1L);
            CommonCourseList.add(math);
        }
        //专业课列表
        List<ExaminationCourse> MajorCourseList = examinationCourseMapper.getMajorCourseList(majorId);
        CommonCourseList.addAll(MajorCourseList);
        return CommonCourseList;
    }
}
